package com.socodethis.spaceex.android.graphics;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.socodethis.spaceex.Assets;

public class Sponge extends Actor {
	
	private boolean _wasTouched = true;

	public Sponge(){
		height = 512;
		width = 512;
	}
	
	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		
		if(_wasTouched)
			batch.setColor(new Color((float)Math.random(), (float)Math.random(), (float)Math.random(), 1));
		
		batch.draw(Assets.manager.get("spongebob.png", Texture.class), this.x, this.y, this.originX, this.originY, this.width, this.height, this.scaleX,
				this.scaleY, this.rotation, 0, 0, (int)this.width, (int)this.height, false,false);
		
		if(_wasTouched)
			batch.setColor(Color.WHITE);
	}
	
	@Override public boolean touchDown (float x, float y, int pointer) {
		_wasTouched = !_wasTouched;
		return true;
	}
	
	
	@Override
	public void act(float delta) {
		if(_wasTouched)
			this.rotation += 1;
	}

	@Override
	public Actor hit(float x, float y) {
		if (x > 0 && x < width) if (y > 0 && y < height)
			return this;
		
		return null;
	}

}
